package com.powernode.service.impl;

import com.powernode.domain.Category;
import com.powernode.domain.Product;
import com.powernode.domain.ProductImg;
import com.powernode.mapper.ProductImgMapper;
import com.powernode.mapper.ProductMapper;
import com.powernode.service.ProductService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ProductServiceImpl implements ProductService{

    /**
     * 商品mapper
     */
    @Autowired
    private ProductMapper productMapper;

    /**
     * 商品图片mapper
     */
    @Autowired
    private ProductImgMapper productImgMapper;

    @Override
    public List<Product> selectRecommGoods() {
        List<Product> list =  productMapper.selectRecommGoods();
        if (list.size()==0){
            return list;
        }
        //查询图片集合
        list.forEach(product -> {
            int i = Integer.parseInt(product.getProductId());
            List<ProductImg> ImgList =productImgMapper.selectImgByProductId(i);
            product.setImgs(ImgList);
        });
        return list;
    }
}
